package com.codejam2012.round1a;

import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;

public class B {

	static int nTest;
	static Scanner scanner;
	static FileWriter writer;
	static File in;
	static File out;
	static int[] nStar;
	static int[] r1;
	static int[] r2;
	static int nStage;
	static int nCurrent;
	
	public static void main(String[] args) throws Exception {
		in = new File("input.txt");
		out = new File("output.txt");
		scanner = new Scanner(in);
		writer = new FileWriter(out);
		
		nTest = scanner.nextInt();
		
		for (int test=1;test<=nTest;++test) {
			writer.write("Case #" + test + ": ");
			
			nStage = scanner.nextInt();
			r1 = new int[nStage];
			r2 = new int[nStage];
			nStar = new int[nStage];
			int maxStar = -1;
			for (int i=0;i<nStage;++i) {
				r1[i] = scanner.nextInt();
				r2[i] = scanner.nextInt();
				nStar[i] = 2;
				if (r2[i] > maxStar) {
					maxStar = r2[i];
				}
			}
			nCurrent = 0;
			int nStep = 0;
			int nComplete = 0;
			int flag = 0;
			int idx = -1;
			
			do {
				int r2Max = -1;
				for (int i=0;i<nStage;++i) {
					if (nStar[i] == 2) {
						if (nCurrent >= r2[i]) {
							idx = i;
							flag = 3;
							break;
						}
						else if (nCurrent >= r1[i]) {
							if (flag < 2) {
								if (r2[i] > r2Max) {
									r2Max = r2[i];
									idx = i;
									flag = 1;
								}
							}
						}
					}
					else if (nStar[i] == 1) {
						if (nCurrent >= r2[i]) {
							if (flag < 3) {
								idx = i;
								flag = 2;
							}
						}
					}
				}
				if (flag == 3) {
					nStar[idx] = 0;
					nComplete++;
					nCurrent += 2;
				}
				else if (flag == 2) {
					nStar[idx] = 0;
					nComplete++;
					nCurrent += 1;
				}
				else if (flag == 1) {
					nStar[idx] = 1;
					nCurrent += 1;
				}
				else {
					flag = -1;
					break;
				}
				nStep++;
				flag = 0;
			} while(nComplete < nStage);
			
			if (flag == -1) {
				writer.write("Too Bad");
			}
			else {
				writer.write(""+nStep);
			}
			if (test<nTest) {
				writer.write("\n");
			}
		}
		
		writer.close();
	}
}
